#!/usr/bin/env python

import sys
import math
import itertools

def main():
    for (gene_id, path_id), grp in itertools.groupby((l.strip().split('\t') for l in sys.stdin), key=lambda spl: (spl[0], spl[1])):
        z_list = [float(i[2]) for i in grp]
        z_avg = sum(z_list) / math.sqrt(len(z_list))
        print "%s\t%s\t%f" % (gene_id, path_id, z_avg)

if __name__ == "__main__":
    main()

